<template>
	<el-dialog title="选择适用默认带出险种方案" :visible.sync="dialogVisible" size="small" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="off">
		  <el-form label-width="150px" >
		  <el-row :span="24">
		  	<el-form-item label="方案代码" label-width="150px" :span="24">
				<el-select v-model="arrayPlancodes" multiple  placeholder="险种代码" filterable size="small" style="width:80%">
					<el-option v-for="item in planOptionsAll" :key="item.plancode" :label="item.riskcode + '-' + item.plancode + '-' + item.plancname" :value="item.plancode"></el-option>
				</el-select>
			</el-form-item>
		  </el-row>
		</el-form>
		  <span slot="footer" class="dialog-footer">
			   <el-button @click="off">取 消</el-button>
			   <el-button type="danger" @click="clear">清 空</el-button>
			   <el-button type="success" @click="select">确 定</el-button>
		  </span>
	</el-dialog>
</template>

<script>

import ClauseAPI from "../../../../js/production/clause/clauseAPI";

  export default {
	data() {
		return {
			dialogVisible: true,
			arrayPlancodes: [],
			planOptions: [],
      planOptionsAll:[],
		}
	},
	mounted() {
		ClauseAPI.queryPlansByRisks(this);
		this.arrayPlancodes = this.$parent.arrayPlancodes;
	},
	methods: {
		select() {
      if (this.arrayPlancodes.indexOf('ALL') >= 0) {
        this.arrayPlancodes = [];
        for(let i = 0; i < this.planOptions.length; i++) {
          if (this.arrayPlancodes.indexOf(this.planOptions[i].plancode) === -1) {
            this.arrayPlancodes.push(this.planOptions[i].plancode);
          }
        }
      }
			this.$parent.arrayPlancodes = [];
			this.$parent.planLabel = '';
			this.$parent.arrayPlancodes = this.arrayPlancodes;
			for(let i = 0; i <this.arrayPlancodes.length - 1; i++) {
				this.$parent.planLabel += this.arrayPlancodes[i] + ",";
			}
			if(this.arrayPlancodes.length > 0) {
				this.$parent.planLabel += this.arrayPlancodes[this.arrayPlancodes.length - 1];
			}
			this.off();
		},
		clear() {
			this.arrayPlancodes = [];
			this.$parent.arrayPlancodes = [];
			this.$parent.planLabel = '';
			this.off();
		},
		off() {
			this.$parent.showPlanSelectDialog = false;
		}
	}
  }
</script>
